<?php
namespace app\madmin\controller;
use app\madmin\model\SystemMemberModel;
use app\madmin\model\SystemGroupModel;

/**
 * 成员控制器
 * @author  黄明杰 vx:HMJ125855
 * @version 20190101
 */
class SystemMember extends PublicBase{

	# 成员列表方法
    public function showList(){
        $SystemMember = new SystemMemberModel;

        $Where = $this->getFormWhere();

        $Admin = $this->checkLogin();

        if($Admin['AdminID'] != 1){
            $Where['member_id'] = ['NEQ', 1];
        }

        $Lists = $SystemMember->mList($Where, 'member_id,member_name,member_user,member_group,member_mobile,member_login,member_ip,member_time,member_state,group_title', config('CNF_LISTPAGE'));

        return $this->fetch('SystemMember/showList', [
            'Lists' => $Lists
        ]);
    }

    # 成员新增方法
    public function showAdd(){
    	$SystemMember = new SystemMemberModel;

        if(request()->isPost()){
            $Param = input('post.');

            $Back = $SystemMember->mAdd($Param);

            $this->ShowData($Back['code'], $Back['msgs'], $Back['urls']);
        }else{
            return $this->fetch('SystemMember/showAdd', [
                'Info'  => Null,
                'Group' => $this->showGroup()
            ]);
        }
    }

    # 成员更新方法
    public function showEdit(){
    	$SystemMember = new SystemMemberModel;

        $ID = input('param.id');

        if(request()->isPost()){
            $Param = input('post.');

            $Back = $SystemMember->mEdit(['member_id'=>$ID], $Param);

            $this->ShowData($Back['code'], $Back['msgs'], $Back['urls']);
        }else{
            $Info = $SystemMember->mInfo(['member_id'=>$ID]);

            if(empty($Info)){
                $this->ShowData(2, lang('XtCwCxCw'));
            }

            if($Info['member_login'] > 0){
                $Info['member_login'] = date('Y/m/d H:i:s', $Info['member_login']);
            }else{
                $Info['member_login'] = '- -';
            }

            return $this->fetch('SystemMember/showAdd', [
                'Info'  => $Info,
                'Group' => $this->showGroup()
            ]);
        }
    }

    # 成员删除方法
    public function showDel(){
    	if(request()->isPost()){
            $SystemMember = new SystemMemberModel;

            $ID = input('post.id');

            $Back = $SystemMember->mDel(['member_id'=>$ID]);

            $this->ShowData($Back['code'], $Back['msgs']);
        }
    }

    # 权限列表方法
    private function showGroup(){
        $SystemGroup = new SystemGroupModel;

        $Where = [];
        $Where['group_state'] = 1;

        $Admin = $this->checkLogin();

        if($Admin['AdminID'] != 1){
            $Where['group_id'] = ['NEQ', 1];
        }

        return $SystemGroup->mAll($Where, 'group_id,group_title');
    }

}